package com.example.administrator.asdasd;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;


public class Fragment_gr extends Fragment {
    private TextView tt1;
    private TextView tt2;
    private TextView tt3;

    private Button btn1;

    public String str2;
    public String str3;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.new_user, container, false);

        tt1 = (TextView) view.findViewById(R.id.new_userName);
        tt2 = (TextView) view.findViewById(R.id.new_userId);
        tt3 = (TextView) view.findViewById(R.id.new_phoneNum);
        btn1 = (Button) view.findViewById(R.id.new_edit);
        tt1.setText(MainActivity.name);

        SQLdm s = new SQLdm();
        SQLiteDatabase db = s.openDatabase(getActivity().getApplication());
        Cursor c = db.rawQuery("select * from grtb where name=?", new String[]{MainActivity.name});
        while (c.moveToNext()) {
            str2 = c.getString(c.getColumnIndex("ren_name"));
            str3 = c.getString(c.getColumnIndex("num"));
        }
        db.close();
        if (!str2.equals("")) {
            tt2.setText(str2);
        }
        if (!str3.equals(""))
        {
            tt3.setText(str3);
        }
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.Mythis, New_user.class);
                intent.putExtra("name", MainActivity.name);
                //startActivity(intent);
                startActivityForResult(intent, 0);
            }
        });

        return view;

    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        SQLdm s = new SQLdm();
        SQLiteDatabase db = s.openDatabase(getActivity().getApplication());
        Cursor c = db.rawQuery("select * from grtb where name=?", new String[]{MainActivity.name});
        while (c.moveToNext()) {
            str2 = c.getString(c.getColumnIndex("ren_name"));
            str3 = c.getString(c.getColumnIndex("num"));
        }
        db.close();
        tt1.setText(MainActivity.name);
        if (!str2.equals("")) {
            tt2.setText(str2);
        }
        else {
            tt2.setText("未设置");
        }
        if (!str3.equals(""))
        {
            tt3.setText(str3);
        } else {
            tt3.setText("未设置");
        }

    }
}